import { FC } from "react";
import { Routes, Route, Navigate, useLocation } from 'react-router-dom'
import Index from './layout/Index'
import { useAppSelector } from "./store/hooks";
import {Index as Login} from './views/login/Index'
type AppProps = {}

const App: FC = (props: AppProps) => {

const loginState = useAppSelector(state => state.user.loginState)

const {search} = useLocation() 
const redirectUrl = search.split('?r=')[1] 
const str = redirectUrl ? redirectUrl : '/'
return (
 <Routes>
   <Route path="/login" element = { loginState ? <Navigate to={str} /> : <Login /> } />
   <Route path="/*" element = { loginState ? <Index /> : <Navigate to="/login" /> } />
 </Routes>
)
}

export default App